﻿using Microsoft.Extensions.Logging;
using Quartz;
using System;
using System.Threading.Tasks;
using KwaiXiaoDian.IService;

namespace KwaiXiaoDian.Job.Jobs
{
    /// <summary>
    /// 同步商品详情job
    /// </summary>
    [DisallowConcurrentExecution]
    public class SyncProductDetailJob : IJob
    {
        private readonly ILogger<SyncProductDetailJob> _logger;
        private readonly IProductService _productService;

        public SyncProductDetailJob(ILogger<SyncProductDetailJob> logger, IProductService productService)
        {
            _logger = logger;
            _productService = productService;
        }

        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                _productService.SyncProductDetail();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, string.Format("定时同步商品详情时发生异常，message:{0}", ex.Message));
            }
            return Task.CompletedTask;
        }
    }
}
